/**
 * 
 */
package com.gwcloud.leetcode.interview100;

/**
 * @ClassName   : Leetcode0334 
 * @author      : ganwei 
 * @date        : 2020年5月30日
 * @Description : Leetcode0334
 */
public class Leetcode0334 {
    /**
     * -暴力算法，但是AC超时
     */
	public boolean increasingTriplet(int[] nums) {
    	if(nums.length < 3){
    		return false;
    	}
    	for(int i = 0; i < nums.length; i++){
    		for(int j = i+1; j < nums.length; j++){
    			for(int k = j+1; k < nums.length; k++){
    				if(nums[i] < nums[j] && nums[j] < nums[k]){
    					return true;
    				}
    			}
    		}
    	}
    	return false;
    }
	/**
	 * -解题思路2，
	 */
	public boolean increasingTriplet_1(int[] nums){
		int one = Integer.MAX_VALUE;
		int two = Integer.MAX_VALUE;
		for(int n : nums){
			if(n <= one){
				one = n;
			}else if(n <= two){
				two = n;
			}else{
				return true;
			}
		}
		
		return false;
	}
	
    public static void main(String[] args){
    	Leetcode0334 l0334 = new Leetcode0334();
    	int[] nums = {2,4,-2,-3};
    	l0334.increasingTriplet_1(nums);
    }
}
